﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HaoPeng
{
    public partial class newMachine : Form
    {
        public newMachine()
        {
            InitializeComponent();
        }

        private void newMachine_Load(object sender, EventArgs e)
        {
            BindCombo();
        }

        private void BindCombo()
        {
            string sql = "select * from tree_Machine";
            try
            {
                DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql).Tables[0];
                comboBox1.ValueMember = "MachineName";
                comboBox1.DisplayMember = "MachineName";
                comboBox1.DataSource = dt;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("绑定设备combo失败：" + ex.Message);
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "insert into Machine(MachineName, MachineType, MachineEnglishName, IP, Text1, Text2, Text3, Text4, Text5, Text6, Text7, Text8, Text9, Text10, Text11, Text12, Text13, Text14, Text15, Text16, Text17, Text18, Text19, Text20) " +
                "values (@MachineName, @MachineType, @MachineEnglishName, @IP, @Text1, @Text2, @Text3, @Text4, @Text5, @Text6, @Text7, @Text8, @Text9, @Text10, @Text11, @Text12, @Text13, @Text14, @Text15, @Text16, @Text17, @Text18, @Text19, @Text20)";
            try
            {
                int result = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql,
                    new SqlParameter("@MachineName", textBox1.Text),
                    new SqlParameter("@MachineType", comboBox1.SelectedValue),
                    new SqlParameter("@MachineEnglishName", textBox3.Text),
                    new SqlParameter("@IP", textBox4.Text),
                    new SqlParameter("@Text1", textBox5.Text),
                    new SqlParameter("@Text2", textBox6.Text),
                    new SqlParameter("@Text3", textBox7.Text),
                    new SqlParameter("@Text4", textBox8.Text),
                    new SqlParameter("@Text5", textBox9.Text),
                    new SqlParameter("@Text6", textBox10.Text),
                    new SqlParameter("@Text7", textBox11.Text),
                    new SqlParameter("@Text8", textBox12.Text),
                    new SqlParameter("@Text9", textBox13.Text),
                    new SqlParameter("@Text10", textBox14.Text),
                    new SqlParameter("@Text11", textBox15.Text),
                    new SqlParameter("@Text12", textBox16.Text),
                    new SqlParameter("@Text13", textBox17.Text),
                    new SqlParameter("@Text14", textBox18.Text),
                    new SqlParameter("@Text15", textBox19.Text),
                    new SqlParameter("@Text16", textBox20.Text),
                    new SqlParameter("@Text17", textBox21.Text),
                    new SqlParameter("@Text18", textBox22.Text),
                    new SqlParameter("@Text19", textBox23.Text),
                    new SqlParameter("@Text20", textBox24.Text));
                MessageBox.Show("共更新了" + result + "条数据！");
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("新增设备数据失败：" + ex.Message);
                MessageBox.Show(ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        
    }
}
